package starlingui.component.itemRender
{
	import com.imcrl.component.drager.DragManager;
	import com.imcrl.component.drager.IDraggingImage;
	import com.imcrl.component.itemRender.DragableItemRender;
	import com.imcrl.core.ChooseState;
	import com.imcrl.core.StarlingHelper;
	import com.imcrl.event.DragAndDropEvent;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import starling.animation.Tween;
	import starling.core.Starling;
	import starling.events.Event;
	import starling.events.Touch;
	import starling.events.TouchEvent;
	import starling.events.TouchPhase;
	import starling.text.BitmapFont;
	import starling.text.TextField;
	import starling.textures.Texture;
	import starling.utils.HAlign;
	import starling.utils.VAlign;
	
	import starlingui.component.drag.AbsIcon;
	import starlingui.component.drag.AbsSlot;
	import starlingui.vo.IconVO;
	
	public class IconItemRender extends DragableItemRender
	{		
		private var vo:IconVO;
		public function IconItemRender()
		{
			setDragEnabled(true);
			setDropTrigger(true);
		}
		
		override protected function start(event:DragAndDropEvent):void{
		}
		
		private var propertysTween:Tween;
		public function tweenPropertys(propertys:Array,values:Array,time:Number=0.3):void{
			Starling.juggler.remove(propertysTween);
			
			if(propertysTween==null){
				propertysTween=new Tween(this,time);
			}else{
				propertysTween.reset(this,time);
			}
			var len:int=propertys.length;
			for(var i:int=0;i<len;i++){
				propertysTween.animate(propertys[i],values[i]);
			}
			Starling.juggler.add(propertysTween);
		}
		
		override public function set chooseState(value:int):void
		{
			if(value==ChooseState.SELECT){
				icon.color=0xFF990000;
			}else{
				icon.color=0xFFFFFFFF;
			}
			_chooseState=value;
		}
		
		override protected function gotoAndStop(frame:int):void{
			//trace(frame);
		}
		
		override public function set data(value:*):void{
			super.data=value;
			vo=value;
			
			if(vo.sub.length>0){
				icon.load(IconVO.FOLDER_PATH);
			}else{
				icon.load(vo.icon);
			}
		}
		
		public function injectStart(item:IconItemRender):void{
			//转换为文件夹结构状态
			chooseState=ChooseState.SELECT;
		}
		
		public function injectEnd(item:IconItemRender):void{
			//如果有项，就做填充，没有项就关闭文件夹结果状态;
			chooseState=ChooseState.UNSELECT;
		}
		
		public function get isFull():Boolean{
			return vo.sub.length>=IconVO.FOLDER_FULL_COUNT;
		}
		
		public function get isFolder():Boolean{
			return vo.sub.length>0;
		}
		
		private var mTextField:TextField;
		public function debug(value:String):void{
			if(mTextField==null){
				mTextField = new TextField(128, 32, "", BitmapFont.MINI, BitmapFont.NATIVE_SIZE, 0x0);
				mTextField.fontSize=22;
				mTextField.hAlign=HAlign.LEFT;
				this.addChild(mTextField);
			}
			mTextField.text=value;
		}
	}
}